﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTBS.Models.Entities;
using FTBS.Models.Entities.Concert;

namespace FTBS.Models.DAO
{
    public class TicketDetailsConcertEntityDAO
    {
        private FilmTicketBookingSystemEntities _entities = new FilmTicketBookingSystemEntities();
        public List<TicketDetailsConcertEntity> LoadTicketsByCartId(string id)
        {
            List<TicketDetailsConcertEntity> listResult = new List<TicketDetailsConcertEntity>();
            var resultQuery = from ticket in _entities.Tickets
                              join chair in _entities.Chairs on ticket.ChairId equals chair.ChairId
                              join chairType in _entities.ChairTypes on chair.ChairTypeId equals chairType.ChairTypeId
                              join schedule in _entities.Schedules on ticket.ScheduleId equals schedule.ScheduleId
                              join theater in _entities.Theaters on schedule.TheaterId equals theater.TheaterId
                              join showTime in _entities.ShowTimes on schedule.ShowTimeId equals showTime.ShowTimeId
                              join film in _entities.Films on schedule.FilmId equals film.FilmId
                              join room in _entities.Rooms on schedule.RoomId equals room.RoomId
                              where ticket.CartId == id
                              select new
                              {
                                  Tickets = ticket,
                                  FilmName = film.Name,
                                  RoomName = room.RoomName,
                                  TheaterName = theater.TheaterName,
                                  //VuongVT: Sửa cột Date từ bảng ShowTime qua bảng Schedule
                                  DateForShow = schedule.Date,
                                  TimeForShow = showTime.Time,
                                  Position = chair.ChairPosition,
                                  ChairTypeName = chairType.TypeName
                              };
            foreach (var item in resultQuery.ToList())
            {
                TicketDetailsConcertEntity ticketDetailsEntity = new TicketDetailsConcertEntity();
                ticketDetailsEntity.FilmName = item.FilmName;
                ticketDetailsEntity.RoomName = item.RoomName;
                ticketDetailsEntity.TheaterName = item.TheaterName;
                ticketDetailsEntity.DateForShow = item.DateForShow.ToShortDateString();
                ticketDetailsEntity.TimeForShow = item.TimeForShow.ToString(@"hh\:mm");
                ticketDetailsEntity.Position = item.Position;
                ticketDetailsEntity.ChairTypeName = item.ChairTypeName;
                listResult.Add(ticketDetailsEntity);
            }
            return listResult;

        }
    }
}